﻿using DAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 纺织贸易管理系统;

namespace BLL
{
  public   class 架子BLL
    {
        public static  void 架子出库(List<danjumingxitable> listmingxi )
        {
            foreach (var m in listmingxi)
            {
                var kuweis = listmingxi.Where(x => !string.IsNullOrWhiteSpace(x.Kuwei)).Select(x => x.Kuwei).Distinct().ToList();
                foreach (var item in kuweis)
                {
                    Connect.dbcontext.Deleteable<JiaziTable>().Where(x => x.JiaziID == item).ExecuteCommand();
                }    
                //JiaziTableService.UpdateJiaziTable($"State='{danju.ksmc}'", );
            }
        }
        public static void 架子入库(List<danjumingxitable> listmingx)
        {
            //架子入库
            var jiazilist = new List<JiaziTable>();
            foreach (string jiazi in listmingx.Where(x => !string.IsNullOrWhiteSpace(x.Kuwei)).Select(x => x.Kuwei).Distinct().ToList())
            {
                jiazilist.Add(new JiaziTable() { Guisuo = string.Empty, JiaziID = jiazi, State = "公司" });
            }
            Connect.dbcontext.Insertable<JiaziTable>(jiazilist).ExecuteCommand();
        }
        public static void 删除日志(string danhao)
        {
            Connect.dbcontext.Deleteable<ZhijiaMingxiTable>().Where(x => x.Danhao == danhao).ExecuteCommand();
           // ZhijiaMingxiTableService.DeleteZhijiaMingxiTable(x => x.Danhao == danhao);
        }
        public static void 进仓日志(List<danjumingxitable> listmingxi, DanjuTable danju) 
        {
            foreach(var m in listmingxi)
            {
                if (!string.IsNullOrWhiteSpace(m.Kuwei))
                {
                    Connect.dbcontext.Insertable(new ZhijiaMingxiTable()
                    {
                        Danhao = danju.dh,
                        Bianhao = m.Kuwei.ToString(),
                        _date = danju.rq,
                        Remarker = m.beizhu,
                        Leixing = "入库",
                        Kehu = danju.ksmc,
                        CarNum = danju.CarNum
                    }).ExecuteCommand();
                }
            }
           
        }
        public static void 出仓日志(List<danjumingxitable> listmingxi, DanjuTable danju)
        {
            foreach (var m in listmingxi)
            {
                if (!string.IsNullOrWhiteSpace(m.Kuwei))
                {
                    Connect.dbcontext.Insertable(new ZhijiaMingxiTable()
                    {
                        Danhao = danju.dh,
                        Bianhao = m.Kuwei.ToString(),
                        _date = danju.rq,
                        Remarker = m.beizhu,
                        Leixing = "出库",
                        Kehu = danju.ksmc,
                        CarNum = danju.CarNum,
                        
                    }).ExecuteCommand();
                }
            }

        }
    }
}
